﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using ClassLibrary.DAO;
using ClassLibrary.Entity;
using System.Collections.Generic;

public partial class Client_UserControl_ucOrderDetails : System.Web.UI.UserControl
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            if ((Session[Global.SESSION_SHIPTO] == null) || (Session[Global.SESSION_TOTAL] == null) || (Session[Global.SESSION_CART] == null))
            {
                Response.Redirect("~/viewCart.aspx");
            }
            else
            {
                List<TblOrderDetail> arrItems = new List<TblOrderDetail>();
                if (Session[Global.SESSION_CART] != null)
                    arrItems = (List<TblOrderDetail>)Session[Global.SESSION_CART];
                grdShoppingCart.DataSource = arrItems;
                grdShoppingCart.DataBind();
                TblShippTo shipto;
                if (Session[Global.SESSION_SHIPTO] == null)
                    shipto = new TblShippTo();
                else
                    shipto = (TblShippTo)Session[Global.SESSION_SHIPTO];
                Session[Global.SESSION_SHIPTO] = shipto;

                lb_name.Text = shipto.Name;
                lb_phone.Text = shipto.Phone;
                lb_address.Text = shipto.Address;
                lb_email.Text = ((TblUserAccount)Session[Global.SESSION_LOGGED_USER]).Email;
                lb_OrderDate.Text = DateTime.Now.ToString("dd/MM/yyyy");

                //float dDeliveryFee = 0;
                //dDeliveryFee = float.Parse(((TblShippTo)Session[Global.SESSION_SHIPTO]).DeliveryFee.ToString());

                //lblDeliveryFee.Text = dDeliveryFee.ToString("c");

                lblTotal.Text = (float.Parse(Session[Global.SESSION_TOTAL].ToString())).ToString("c");
            }

        }
    }
    protected override void OnError(EventArgs e)
    {
        base.OnError(e);
        Exception err = Server.GetLastError();
        if (err != null)
        {
            Session[Global.SESSION_ERROR] = err;
            Response.Redirect(Global.ERROR_PAGE, true);
        }
    }

    protected void btnNext_Click(object sender, EventArgs e)
    {
        Response.Redirect(string.Format("~/viewCart.aspx"), true);
    }


    protected void btnNext_Click(object sender, ImageClickEventArgs e)
    {
        // Response.Redirect("~/PaymentANZ.aspx", true);
        ScriptManager.RegisterStartupScript(btnNext, btnNext.GetType(), "ScriptLoginSuccess", "UpdatePayment();", true);
    }

    protected void grdShoppingCart_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            e.Row.Cells[0].Text = (e.Row.RowIndex + 1).ToString();
        }
    }
    protected void btnBack_Click(object sender, ImageClickEventArgs e)
    {
        Response.Redirect("~/Client/ShippingTo.aspx", true);
    }
}
